<!--
 * @Author: your name
 * @Date: 2022-03-14 19:35:44
 * @LastEditTime: 2022-03-14 20:13:58
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \geyao\geyao\数组方法slice220314.html
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>数组方法slice</title>
</head>
<body>
  <script>
     var geyao=["1","2","3","4"]
    var geyaotest=["1","2","3","4"]
    var geyaofangfang=["1","2","3","4"]
    var fangfang=["1","2","3","4"]
    var fangfangTest=["1","2","3","4"]
  

    //arr.slice([begin[, end]]) slice() 方法返回一个新的数组对象，这一对象是一个由 begin 和 end 决定的原数组的浅拷贝
    //从第一个位置开始截取到最后一个位置
    console.log( geyao.slice(1),"geyao") // [ "2", "3", "4" ]
    //从第一个位置截止到第二个位置
    console.log( geyaotest.slice(1,2),"geyaotest") // [ "2" ]
    //从第一个位置截取到最后一个位置
    console.log( geyaofangfang.slice(1,5),"geyaofangfang") // [ "2", "3", "4" ]
    //从最后一个位置开始截取
    console.log( fangfang.slice(-1),"fangfang") // [  "4" ]
    //从最后一个位置开始截取 截取当前倒数第二个
    console.log( fangfangTest.slice(-2,-1),"fangfangTest") // [ "3" ]
  </script>
</body>
</html>